package com.azt.api.pojo;

import com.azt.pojo.BaseEntity;
import com.xiaoleilu.hutool.util.StrUtil;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

@Table(name = "u_file")
public class File extends BaseEntity{


    public static final String fileSuffixes = "doc,docx,xls,xlsx,ppt,pptx,zip,rar";//文件后缀

    public static final String imageSuffixes = "gif,jpg,jpeg,bmp,png";//图片后缀

    /**
     * 文件夹ID
     */
    @Column(name="folderId")
    private Integer folderId;

    /**
     * 用户ID
     */
    @Column(name="userId")
    private Integer userId;

    /**
     * 文件名
     */
    @Column(name="fileName")
    private String fileName;

    /**
     * 文件地址
     */
    @Column(name="url")
    private String url;

    /**
     * 后缀
     */
    @Column(name="suffix")
    private String suffix;


    @Column(name="isImage")
    private Integer isImage;


    @Column(name="removed")
    private Integer removed = 0;

    @Transient
    private boolean isFile = true;//是否是文件，不是的话就是图片

    public static final Integer NO_REMOVED = 0;
    public static final Integer IS_REMOVED = 1;



    /**
     * 获取文件夹ID
     *
     * @return folderId - 文件夹ID
     */
    public Integer getFolderId() {
        return folderId;
    }

    /**
     * 设置文件夹ID
     *
     * @param folderId 文件夹ID
     */
    public void setFolderId(Integer folderId) {
        this.folderId = folderId;
    }

    /**
     * 获取用户ID
     *
     * @return userId - 用户ID
     */
    public Integer getUserId() {
        return userId;
    }

    /**
     * 设置用户ID
     *
     * @param userId 用户ID
     */
    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    /**
     * 获取文件名
     *
     * @return fileName - 文件名
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * 设置文件名
     *
     * @param fileName 文件名
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * 获取文件地址
     *
     * @return url - 文件地址
     */
    public String getUrl() {
        return url;
    }

    /**
     * 设置文件地址
     *
     * @param url 文件地址
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * 获取后缀
     *
     * @return suffix - 后缀
     */
    public String getSuffix() {
        return suffix;
    }

    /**
     * 设置后缀
     *
     * @param suffix 后缀
     */
    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }

    public Integer getIsImage() {
        return isImage;
    }

    public void setIsImage(Integer isImage) {
        this.isImage = isImage;
    }

    public Integer getRemoved() {
        return removed;
    }

    public void setRemoved(Integer removed) {
        this.removed = removed;
    }

    public boolean getIsFile() {
        if(StrUtil.isNotBlank(this.suffix) && imageSuffixes.indexOf(this.suffix.toLowerCase()) > -1){
            isFile = false;//为图片
        }
        return isFile;
    }

    public void setFile(boolean file) {
        isFile = file;
    }
}